package com.commons.model;

import java.io.Serializable;

/**
 * Created by jian.zhou on 2016/12/21.
 */
public class Page<T> implements Serializable {
    private static final long serialVersionUID = -4221387216744433913L;
    private int showCount = 10;
    /**总页数**/
    private int totalPage;
    /**总结果数**/
    private int totalResult;
    /**当前页数 **/
    private int currentPage;
    /**当前结果数量*/
    private int currentResult;
    private boolean entityOrField;
    /***db数据***/
    private T object;

    public int getTotalPage()
    {
        if (this.totalResult % this.showCount == 0) this.totalPage = (this.totalResult / this.showCount);
        else this.totalPage = (this.totalResult / this.showCount + 1);
        return this.totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getTotalResult() {
        return this.totalResult;
    }

    public void setTotalResult(int totalResult) {
        this.totalResult = totalResult;
    }

    public int getCurrentPage() {
        if (this.currentPage <= 0) this.currentPage = 1;
        //if (this.currentPage > getTotalPage()) this.currentPage = getTotalPage();
        return this.currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getShowCount() {
        return this.showCount;
    }

    public void setShowCount(int showCount) {
        this.showCount = showCount;
    }

    public int getCurrentResult() {
        this.currentResult = ((getCurrentPage() - 1) * getShowCount());
        if (this.currentResult < 0) this.currentResult = 0;
        return this.currentResult;
    }

    public void setCurrentResult(int currentResult) {
        if (currentResult < 0) {
            currentResult = 0;
        }
        this.currentResult = currentResult;
    }

    public boolean isEntityOrField() {
        return this.entityOrField;
    }

    public void setEntityOrField(boolean entityOrField) {
        this.entityOrField = entityOrField;
    }

    public T getObject() {
        return this.object;
    }

    public void setObject(T object) {
        this.object = object;
    }

    public String toString()
    {
        StringBuilder builder = new StringBuilder();
        builder.append("Page [showCount=");
        builder.append(this.showCount);
        builder.append(", totalPage=");
        builder.append(this.totalPage);
        builder.append(", totalResult=");
        builder.append(this.totalResult);
        builder.append(", currentPage=");
        builder.append(this.currentPage);
        builder.append(", currentResult=");
        builder.append(this.currentResult);
        builder.append(", entityOrField=");
        builder.append(this.entityOrField);
        builder.append("]");
        return builder.toString();
    }
}
